import {
	targetUrl
} from "../uitls/request"
//选择并上传图片
export function chooseAndUploadFIle(resolve, reject) {
	//选择图片
	wx.chooseImage({
		count: 1,
		sizeType: ['original'],
		sourceType: ['album', 'camera'],
		success: (res) => {
			//上传
			const tempFile = res.tempFilePaths[0];
			wx.uploadFile({
				url: targetUrl + 'file/upload',
				filePath: tempFile,
				name: 'file',
				success: (res) => resolve(JSON.parse(res.data).data),
				fail: (res) => reject(res)
			})
		}
	})
}
//上传图片
export function uploadFile(data,resolve,reject) {
	wx.uploadFile({
		url: targetUrl + 'file/upload',
		filePath: data,
		name: 'file',
		success: (res) => resolve(res),
		fail: (res) => reject(res)
	})
}